package com.czp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.czp.pojo.Resume;
import com.czp.service.ResumeService;

@Controller
@RequestMapping("/resume")
public class ResumeController {

	@Autowired
	private ResumeService resumeService;

	@GetMapping
	public ModelAndView list() {
		ModelAndView modelAndView = new ModelAndView();
		List<Resume> list = resumeService.findAll();
		modelAndView.addObject("resumes", list);
		modelAndView.setViewName("/WEB-INF/jsp/list.jsp");
		return modelAndView;
	}

	@GetMapping("/delete")
	public String delete(Long id) {
		resumeService.deleteById(id);
		return "redirect:/resume";
	}

	@PostMapping
	public String saveOrUpdate(Resume resume) {
		resumeService.saveOrUpdate(resume);
		return "redirect:/resume";
	}
}
